home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4027 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: c not writing to file
  5. Date: Thu, 01 Feb 1996 14:47:41 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <3110B66D.409E@cmt.lpr.mail.carel.fi>
  8. References: <1996Feb1.115146.24139@river.tay.ac.uk>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  14.  
  15. Mr persil wrote:
  16. > this is a sample of my lines of code
  17. > this should add the variable word to the end of file, but doesn't
  18. > i used a text editor to create the file
  19. >         text1 = fopen(filename,"a");
  20. >         fprintf (text1,word)
  21. >         fclose (text1)
  22. > writes something to the hard disk, but nothing appends to the end of
  23. > the file
  24. > if i create the file using a c program it appends the word to the
  25. > end
  26. > any ideas would be great
  27. > cheers
  28. > the mega me
  29.  
  30. Some editors terminate text files by appending hex 1A (Ctrl+Z) to the end of it. fprintf 
  31. can write past this mark, but TYPE or similar commands don't print what comes after 1A. You 
  32. can check if the file's size changes when you append to it. If this is the case, then you 
  33. can do it like this and have no problems:
  34.  
  35.     1. open the old file for read (text)
  36.     2. create new file for write (text)
  37.     3. read line from the old file
  38.     4. write the line to the new file
  39.     5. if still more rows, go to step 3
  40.     6. add the new stuff to the new file
  41.     7. close both files
  42.     8. delete old file
  43.     9. rename new file to old file's name
  44.  
  45. HTH,
  46.  AriL
  47. -- 
  48. All my opinions are mine and mine alone.
  49.